#ifndef NPCAP_MONITOR_H
#define NPCAP_MONITOR_H

#include <QWidget>
#include "pcap.h"
#include <QTableWidget>
#include <QThread>
#include <QtCore/QReadWriteLock>
class run_npcap : public QThread
{
    Q_OBJECT
public:
    explicit run_npcap(QObject *parent = nullptr);

protected:
    void run();

signals:
    void packet_trig(char * pkg_time,const struct pcap_pkthdr *header,const u_char *pkt_data);
public slots:
    void npcap_sync(const char * d_name);
private:

    char errbuf [PCAP_ERRBUF_SIZE];
    pcap_t *adhandle;
    struct pcap_pkthdr *header;
    const u_char *pkt_data;
    char * pkg_time;
public:
    void set_pcap_enable(bool en);
private:
    bool pcap_enable;
    QReadWriteLock m_lock;
};

namespace Ui {
class npcap_monitor;
}

class npcap_monitor : public QWidget
{
    Q_OBJECT

public:
    explicit npcap_monitor(QWidget *parent = nullptr);
    ~npcap_monitor();

private slots:
    void on_ui_update_dev_clicked();

    void on_ui_open_dev_clicked();

    void on_ui_start_cap_clicked();

    void on_ui_close_cap_clicked();

private:
    Ui::npcap_monitor *ui;
    pcap_if_t * alldevs;
    pcap_if_t * d;
    char errbuf [PCAP_ERRBUF_SIZE];
    QTableWidget *table_devs;
    pcap_t *adhandle;
    bool open_dev_state;
    static void packet_handler(u_char *param, const struct pcap_pkthdr *header, const u_char *pkt_data);
    struct pcap_pkthdr *header;
    const u_char *pkt_data;
    run_npcap *run_npcap_thread;
private slots:
    void on_ui_table_cellClicked(int row,int column);
    void packet_sync(char * pkg_time,const struct pcap_pkthdr *header,const u_char *pkt_data);
signals:
    void npcap_trig(const char * d_name);
};




#endif // NPCAP_MONITOR_H
